package com.atguigu.leetcode;

import java.util.HashMap;
import java.util.Map;

public class leetcode01_hashmap {

    public static int[] twoSum(int[] nums, int target){
        Map<Integer, Integer> map = new HashMap<>(nums.length);
        for (int i = 0; i < nums.length; i++) {
            int parternumber = target - nums[i];
            if (map.containsKey(parternumber)){
                return new int[]{map.get(parternumber),i};
            }
            map.put(nums[i],i);
        }
        return null;


    }
    public static void main(String[] args) {
        int nums[] = new int[]{2,7,11,15};
        int target = 9;
//        System.out.println(twoSum(nums, target).toString());
        for (int i : twoSum(nums, target)) {
            System.out.println(twoSum(nums, target)[i]);

        }
    }
}
